package com.k2data.k2app.controller;

import com.k2data.k2app.domain.po.DeviceSpec;
import com.k2data.k2app.response.CommonResultResponse;
import com.k2data.k2app.response.ResponseHelper;
import com.k2data.k2app.service.DictService;
import com.k2data.k2app.utils.StringUtils;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lidong9144@163.com 17-3-20.
 */
@RestController
@RequestMapping("/dicts")
public class DictController {

    private final DictService dictService;

    @Autowired
    public DictController(DictService dictService) {
        this.dictService = dictService;
    }

    @ApiOperation(value = "设备类型")
    @GetMapping(value = "/device-types")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "value", value = "value", dataType = "string", paramType = "query")
    })
    public ResponseEntity<CommonResultResponse> getDeviceTypes(@RequestParam(value = "value", required = false) String value) throws Exception {
        DeviceSpec cond = new DeviceSpec();
        cond.setParentId(0L);
        cond.setValue(value);

        return ResponseHelper.success(dictService.selectDeviceType(cond));
    }

    @ApiOperation(value = "设备型号")
    @GetMapping(value = "/specs")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "type", dataType = "string", paramType = "query")
    })
    public ResponseEntity<CommonResultResponse> getSpecs(@RequestParam(value = "type", required = false) String type) throws Exception {
        DeviceSpec cond = new DeviceSpec();
        cond.setValue(type);
        if (StringUtils.isBlank(type)) {
            cond.setParentId(0L);
        }

        return ResponseHelper.success(dictService.selectDeviceSpec(cond));
    }

}
